package com.yocard.yxyd.ui.activity;

import com.yocard.yxyd.R;
import com.yocard.yxyd.base.Constants;
import com.yocard.yxyd.ui.activity.base.SimpleActivity;
import com.yocard.yxyd.utils.util.ActivityUtils;
import com.yocard.yxyd.utils.util.CacheDoubleStaticUtils;
import com.yocard.yxyd.utils.util.StringUtils;

/**
 * Created on 2019/4/1.
 */
public class SplashActivity extends SimpleActivity {

    @Override
    protected int getLayout() {
        return R.layout.act_splash;
    }

    @Override
    protected void initEventAndData() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1 * 1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                checkLogin();
            }
        }).start();
    }

    private void checkLogin() {
        String token = CacheDoubleStaticUtils.getString(Constants.KEY_TOKEN);
        if (!StringUtils.isEmpty(token)) {
            ActivityUtils.startActivity(MainActivity.class);
            ActivityUtils.finishActivity(this);
        } else {
            ActivityUtils.startActivity(LoginActivity.class);
            ActivityUtils.finishActivity(this);
        }
    }
}
